//
//  NetworkTools.swift
//  globalcarbusiness
//
//  Created by dongzhenyu on 2017/8/12.
//  Copyright © 2017年 dongzhenyu. All rights reserved.
//

import UIKit
import Alamofire


enum MethodType {
    case get
    case post
}

class NetworkTools {
    
    static let shareInstance: NetworkTools = NetworkTools()
    
    private init() {}
}

extension NetworkTools {
    
    func requestData(_ URLString: String, _ type: MethodType, _ parameters: [String: Any], _ complection: @escaping (Any, _ isSuccess: Bool)-> Void) {
        
        let method = type == .get ? HTTPMethod.get : HTTPMethod.post
        
        Alamofire.request(URLString, method: method, parameters: parameters).responseJSON { (response) in
            
            
            guard let result = response.result.value else {
                print(response.result.error!)
                complection("", false)
                return
            }
            

            complection(result, response.result.isSuccess ? true : false)
            
        }
    }
}
